﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar;
using System.Xml;
using System.Windows.Forms;
//using QuanLyDoanVien.Report;

namespace QuanLyDoanVien.General
{
    public class ThamSo
    {
        public static String DatabaseName;
    }
    #region Xu ly tap tin Xml
    public class XML
    {
        public static XmlDocument ReadXml(String fileName)
        {
            XmlDocument XmlDocument = new XmlDocument();
            try
            {
                XmlDocument.Load(fileName);
            }
            catch
            {
                MessageBoxEx.Show("Không đọc được hoặc không tồn tại tập tin cấu hình " + fileName, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return XmlDocument;
        }

        public static void WriteXml(String fileName, String serverName, String dataBase, String costatus)
        {
            XmlTextWriter XmlWrite = new XmlTextWriter(fileName, null);
            XmlWrite.Formatting = Formatting.Indented;

            XmlWrite.WriteStartDocument();
            XmlWrite.WriteComment("Thong so co ban:\n\t" +
                                "costatus = true : quyen Windows\n\t" +
                                "costatus = false: quyen SQL Server\n\t" +
                                "servname: ten server\n\t" +
                                "username: ten dang nhap he thong\n\t" +
                                "password: mat khau dang nhap he thong\n\t" +
                                "database: ten co so du lieu\n");
            XmlWrite.WriteStartElement("config");

            XmlWrite.WriteStartElement("costatus");
            XmlWrite.WriteString(costatus);
            XmlWrite.WriteEndElement();

            XmlWrite.WriteStartElement("servername");
            XmlWrite.WriteString(serverName);
            XmlWrite.WriteEndElement();

            XmlWrite.WriteStartElement("username");
            XmlWrite.WriteString("");
            XmlWrite.WriteEndElement();

            XmlWrite.WriteStartElement("password");
            XmlWrite.WriteString("");
            XmlWrite.WriteEndElement();

            XmlWrite.WriteStartElement("database");
            XmlWrite.WriteString(dataBase);
            XmlWrite.WriteEndElement();

            XmlWrite.WriteEndElement();
            XmlWrite.WriteEndDocument();

            XmlWrite.Close();
        }

        public static void XMLWriter(String fileName, String serverName, String userName, String passWord, String dataBase, String costatus)
        {
            XmlTextWriter xmlW = new XmlTextWriter(fileName, null);
            xmlW.Formatting = Formatting.Indented;

            xmlW.WriteStartDocument();
            xmlW.WriteComment("\nKhong duoc thay doi noi dung file nay!\n" +
                                "Thong so co ban:\n\t" +
                                "costatus = true : quyen Windows\n\t" +
                                "costatus = false: quyen SQL Server\n\t" +
                                "servname: ten server\n\t" +
                                "username: ten dang nhap he thong\n\t" +
                                "password: mat khau dang nhap he thong\n\t" +
                                "database: ten co so du lieu\n");
            xmlW.WriteStartElement("config");

            xmlW.WriteStartElement("costatus");
            xmlW.WriteString(costatus);
            xmlW.WriteEndElement();

            xmlW.WriteStartElement("servername");
            xmlW.WriteString(serverName);
            xmlW.WriteEndElement();

            xmlW.WriteStartElement("username");
            xmlW.WriteString(userName);
            xmlW.WriteEndElement();

            xmlW.WriteStartElement("password");
            xmlW.WriteString(passWord);
            xmlW.WriteEndElement();

            xmlW.WriteStartElement("database");
            xmlW.WriteString(dataBase);
            xmlW.WriteEndElement();

            xmlW.WriteEndElement();
            xmlW.WriteEndDocument();

            xmlW.Close();
        }

    }
    #endregion
        #region Quy dinh
        public class QuyDinh
        {
            public String LaySTT(int autoNum)
            {
                if (autoNum < 10)
                    return "0000000" + autoNum;
                else if (autoNum >= 10 && autoNum < 10000000)
                    return "000000" + autoNum;
                else if (autoNum >= 100 && autoNum < 10000000)
                    return "00000" + autoNum;
                else if (autoNum >= 1000 && autoNum < 10000000)
                    return "0000" + autoNum;
                else if (autoNum >= 10000 && autoNum < 10000000)
                    return "000" + autoNum;
                else if (autoNum >= 100000 && autoNum < 10000000)
                    return "00" + autoNum;
                else if (autoNum >= 100000 && autoNum < 10000000)
                    return "0" + autoNum;
                else
                    return "";
            }

            private String m_DiaChi;
            public String DiaChi
            {
                get { return m_DiaChi; }
                set { m_DiaChi = value; }
            }
        }
        #endregion
}